
package cn.zlg.common.springmvc.validate.constraints;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;

import cn.zlg.common.springmvc.validate.constraintsvalidator.UniqueInDBValidator;

/**
 * 用于指定值在数据库中是否唯一
 * 一般只用指定table,column即可完成验证，dataType字段暂未扩展
 * 
 * @author zhangxiaohuan
 *
 */
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR,
        ElementType.PARAMETER })
@Constraint(validatedBy = { UniqueInDBValidator.class })
@Retention(RetentionPolicy.RUNTIME)
public @interface UniqueInDB {

    String field() default "";

    String table() default "";

    String column() default "";

    String dataType() default "";

    String message() default "{field.must.be.unique}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}
